package com.qingcheng.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.pojo.order.OrderOrderItem;
import com.qingcheng.pojo.order.SplitOrder;
import com.qingcheng.service.order.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 根据订单id去拆分订单
     * @param id
     * @return
     */
    @PostMapping("/splitOrder")
    public Result splitOrder(String id, List<SplitOrder> splitOrderList){
        orderService.splitOrder(id,splitOrderList);
        return new Result();
    }

    //合并订单
    @PostMapping("/merge")
    public Result merge(String one,String two){
        orderService.merge(one,two);
        return new Result();
    }
    //批量发货
    @PostMapping("/updateOrdersStatus")
    public Result updateOrdersStatus(@RequestBody List<Order> orderList){
        orderService.updateOrdersStatus(orderList);
        return new Result();
    }
    //查询订单状态 0待付款、1待发货、2已发货、3已完成、4已关闭
    @GetMapping("/findOrdersStatus")
    public List<Order> findOrdersStatus(String id){
        return orderService.findOrdersStatus(id);
    }
    //根据id去查询订单信息以及订单详情
    @GetMapping("/findOrderOrderItemByid")
    public OrderOrderItem findOrderOrderItemByid(String id){
       return orderService.findOrderOrderItemByid(id);
    }
    @GetMapping("/findAll")
    public List<Order> findAll(){
        return orderService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Order> findPage(int page, int size){
        return orderService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String,Object> searchMap){
        return orderService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  orderService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Order findById(String id){
        return orderService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        orderService.add(order);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Order order){
        orderService.update(order);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(String id){
        orderService.delete(id);
        return new Result();
    }

}
